package com.sj.uabrowser.mvp.settings.view.act;

import android.content.Intent;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.sj.uabrowser.R;
import com.sj.uabrowser.app.Constant;
import com.sj.uabrowser.app.SPUtil;
import com.sj.uabrowser.app.StatusBarUtil;
import com.sj.uabrowser.app.Util;
import com.sj.uabrowser.framework.BaseActivity;
import com.sj.uabrowser.framework.BasePresenter;

import butterknife.BindView;
import butterknife.OnClick;

public class SettingFontAct extends BaseActivity implements CompoundButton.OnCheckedChangeListener {

    @BindView(R.id.cb12)
    CheckBox cb12;
    @BindView(R.id.cb15)
    CheckBox cb15;
    @BindView(R.id.cb18)
    CheckBox cb18;
    @BindView(R.id.tvEdit)
    TextView tvEdit;

    int fontSize = Constant.FONTSIZE_NORMAL;

    @Override
    public BasePresenter createPresenter() {
        return null;
    }

    @Override
    public int getLayoutID() {
        return R.layout.activity_setting_font;
    }

    @Override
    public void setView() {
        StatusBarUtil.setTranslucentForImageViewInFragment(this,0,null);
        StatusBarUtil.setLightMode(this);
        setTopTitle("字体大小");
        tvEdit.setTextColor(getResources().getColor(R.color.colorPrimary));
        tvEdit.setText("保存");
        fontSize = SPUtil.get(this, SPUtil.KEY_FONTSIZE, Constant.FONTSIZE_NORMAL);
        setSelectCB();
        cb12.setOnCheckedChangeListener(this);
        cb15.setOnCheckedChangeListener(this);
        cb18.setOnCheckedChangeListener(this);
    }

    private void setSelectCB() {
        cb12.setChecked(false);
        cb15.setChecked(false);
        cb18.setChecked(false);
        switch (fontSize) {
            case Constant.FONTSIZE_SMALL:
                cb12.setChecked(true);
                break;
            case Constant.FONTSIZE_NORMAL:
                cb15.setChecked(true);
                break;
            case Constant.FONTSIZE_LARGE:
                cb18.setChecked(true);
                break;
        }
    }

    @Override
    public void setData() {

    }

    @OnClick({R.id.tv_save,R.id.tvEdit})
    public void onClick(View view) {
        startIconAnim(view);
        if (cb12.isChecked()) {
            SPUtil.put(this, SPUtil.KEY_FONTSIZE, Constant.FONTSIZE_SMALL);
        } else if (cb15.isChecked()) {
            SPUtil.put(this, SPUtil.KEY_FONTSIZE, Constant.FONTSIZE_NORMAL);
        } else if (cb18.isChecked()) {
            SPUtil.put(this, SPUtil.KEY_FONTSIZE, Constant.FONTSIZE_LARGE);
        }
        showToast("字体大小设置成功！");
        finish();
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if(isChecked) {
            cb12.setEnabled(false);
            cb15.setEnabled(false);
            cb18.setEnabled(false);
            switch (buttonView.getId()) {
                case R.id.cb12:
                    cb15.setChecked(false);
                    cb18.setChecked(false);
                    cb15.setEnabled(true);
                    cb18.setEnabled(true);
                    break;
                case R.id.cb15:
                    cb12.setChecked(false);
                    cb18.setChecked(false);
                    cb12.setEnabled(true);
                    cb18.setEnabled(true);
                    break;
                case R.id.cb18:
                    cb15.setChecked(false);
                    cb12.setChecked(false);
                    cb15.setEnabled(true);
                    cb12.setEnabled(true);
                    break;
            }
        }
    }
}
